package test

object cc {
  def main(args:Array[String]):Unit={
    val  listBy =List(1,2,3,4)
    println(listBy.groupBy(_%2))

    val string ="abs"
    println(string.charAt(0))
 //根据单词首字母进行分组
    val stringList = List("abc","abd","asdf","sdf")
    println(stringList.groupBy(_.charAt(0)))


    //练习：找出搜索关键词的top3
   // val keyWord = List("iu","amy","tom and jack","jack","iu")
    //1.扁平映射转换为一维的单词列表
   // val keyWord1 = keyWord.flatMap(_.split(" "))
   // println(keyWord1)
    //2.将相同的单词划分为一组
   // val keyWord2 = keyWord.groupBy(word => word)
   // println(keyWord2)
    //3.找到单词最多的list
   // val countKey = keyWord2.map(k =>(k._1,k._2.length))
    //println(countKey)
    //4.去关键词的前三   将map转换为list
   // val keyList = countKey.toList.sortWith(_._2 >_._2).take(3)
   // println(keyList)

    //找出word.txt中出现次数最多的单词
    val keyWord = List("scala/word.txt")



  }




}
